package com.huawei.user.controller;


import com.huawei.user.VO.UserVO;
import com.huawei.user.entry.User;
import com.huawei.user.service.UserService;
import com.huawei.user.util.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "/user")
@Api(tags = "用户模块")
public class UserController {
    @Autowired
    UserService userService;

    @Autowired
    RedisUtil redisUtil;


    @ApiOperation(value = "测试接口")
    @GetMapping("/test")
    public String test() {
        return "hello";
    }


    @ApiOperation(value = "通过手机号获取用户接口")
    @GetMapping("/getUser/{phone}/{region}")
    public List<User> selectUser(@PathVariable String phone,@PathVariable String region) {
        //获取用户信息
        long start = System.currentTimeMillis();
        User user = userService.getUser(phone,region);
        long end = System.currentTimeMillis();
        System.out.println("查询用户信息，耗时：" + (end - start) + "毫秒");
        List users = new ArrayList();
        users.add(user);
        return users;
    }


    @ApiOperation(value = "修改用户信息")
    @PostMapping("/updateUser")
    public void updateUser(@RequestBody UserVO userVO) {
        //修改用户信息
        long start = System.currentTimeMillis();
        userService.updateUser(userVO);
        long end = System.currentTimeMillis();
        System.out.println("查询用户信息，耗时：" + (end - start) + "毫秒");
    }


}
